package netty.test19Channelhandler;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import netty.test22TcpSelfProto.MyMessageEncoder;

/**
 * 执行的是入站操作，所以先从handler链表的 头部向尾部执行，所以下面的handler先执行
 * MyServerByteDecoder 再执行 MyServerHandler
 */
public class MyServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();
        System.out.println("init channel ---->");
        //1,这里加个自定义的解码器 inBound的
        pipeline.addLast(new MyLongDecoder());
        //2,编码器(和客户端的编码器通用)
        pipeline.addLast(new MyMessageEncoder());
        //2,加一个自定的hander 处理业务逻辑
        pipeline.addLast(new MyServerHandler());
    }
}
